<template>
  <div class="personal">
    <router-link :to="/mypersonalEdit/ + currentUser.id">
      <div class="profile">
        <img :src="currentUser.head_img" alt />
        <div class="profile-center">
          <div class="name">
            <span
              class="iconfont"
              :class="[
                currentUser.gender == 1 ? 'iconxingbienan' : 'iconxingbienv',
              ]"
            ></span
            >{{ currentUser.nickname }}
          </div>
          <div class="time">{{ currentUser.date | dateFilter("/") }}</div>
        </div>
        <span class="iconfont iconjiantou1"></span>
      </div>
    </router-link>
    <mycell
      title="我的关注"
      desc="关注的用户"
      @click.native="$router.push({ path: '/myfollows' })"
    ></mycell>
    <mycell title="我的跟帖" desc="跟帖/回复"></mycell>
    <mycell
      title="我的收藏"
      desc="文章/视频"
      @click.native="$router.push({ path: '/myuserStar' })"
    ></mycell>
    <mycell title="设置"></mycell>
    <mybutton type="danger" class="edit" @click="edit">退出</mybutton>
  </div>
</template>

<script>
import mycell from "@/components/mycell";
import mybutton from "@/components/mybutton";
import { userDetail } from "@/api/user";
import axios from "@/utils/request.js";
import { dateFilter } from "@/utils/myfilters.js";

export default {
  data() {
    return {
      currentUser: {},
    };
  },
  components: {
    mycell,
    mybutton,
  },
  filters: {
    dateFilter,
  },
  mounted() {
    /*  console.log(this.$route.params.id); */
    userDetail(this.$route.params.id)
      .then((res) => {
        console.log(res);
        this.currentUser = res.data.data;
        /* console.log(this.currentUser); */
        this.currentUser.head_img = this.currentUser.head_img
          ? axios.defaults.baseURL + this.currentUser.head_img
          : "http://img1.imgtn.bdimg.com/it/u=3757784226,1202878475&fm=26&gp=0.jpg";
        /* http://img1.imgtn.bdimg.com/it/u=3757784226,1202878475&fm=26&gp=0.jpg */
        //添加数据 date
        this.currentUser.date = new Date();
      })
      .catch((err) => {
        console.log(err);
      });
  },
  methods: {
    edit() {
      //删除token
      localStorage.removeItem("userKey");
      //重定向
      this.$router.push({ path: "/login" });
    },
  },
};
</script>

<style lang='less' scoped>
.personal {
  width: 100vw;
  height: 100vh;
  background-color: #eee;
}
a {
  color: #666;
}
.profile {
  display: flex;
  padding: 20px 10px;
  justify-content: space-between;
  align-items: center;
  border-bottom: 5px #ddd solid;
  img {
    width: 70 / 360 * 100vw;
    height: 70 / 360 * 100vw;
    border-radius: 50%;
  }

  .profile-center {
    flex: 1;
    padding: 0 10px;
  }

  .name {
    span {
      color: #75b9eb;
    }
  }

  .time {
    color: #666;
    font-size: 14px;
    margin-top: 5px;
  }
}
.edit {
  margin-top: 20px;
}
</style>
